﻿// <copyright file="GuiHelper.cs" company="ThorIndustry">Copyright (c) ThorIndustry. All rights reserved.</copyright>

public class GuiHelper
{
    public static UnityEngine.Rect FormatGuiTextArea(UnityEngine.GUIText guiText, float maxAreaWidth)
    {
        string[] words = guiText.text.Split(' ');
        string result = "";
        UnityEngine.Rect textArea = new UnityEngine.Rect();

        for (int i = 0; i < words.Length; i++)
        {
            // Set the gui text to the current string including new word.
            guiText.text = (result + words[i] + " ");

            // Measure it.
            textArea = guiText.GetScreenRect();

            // If it didn't fit, put word onto next line, otherwise keep it.
            if (textArea.width > maxAreaWidth)
            {
                result += ("\n" + words[i] + " ");
            }
            else
            {
                result = guiText.text;
            }
        }

        return textArea;

    }

    public static float GetScreenSizeRatio()
    {
        // When using a pc, the dpi is not initialized. otherwise, use the dpi...
        if (UnityEngine.Screen.dpi == 0)
        {
            return UnityEngine.Screen.width / 840.0f;
        }

        return UnityEngine.Screen.dpi / 160.0f;
    }
}
